home *** CD-ROM | disk | FTP | other *** search
- function PROT_ListWarden(listManager) {
- this.debugZone = "listwarden";
- this.listManager_ = listManager;
- this.prefs_ = new G_Preferences();
- this.blackTables_ = [];
- this.whiteTables_ = [];
- this.sandboxUpdates_ = [];
- }
- PROT_ListWarden.prototype.enableBlacklistTableUpdates = function() {
- this.listManager_.enableUpdateTables(this.blackTables_);
- }
- PROT_ListWarden.prototype.disableBlacklistTableUpdates = function() {
- this.listManager_.disableUpdateTables(this.blackTables_);
- }
- PROT_ListWarden.prototype.enableWhitelistTableUpdates = function() {
- this.listManager_.enableUpdateTables(this.whiteTables_);
- }
- PROT_ListWarden.prototype.disableWhitelistTableUpdates = function() {
- this.listManager_.disableUpdateTables(this.whiteTables_);
- }
- PROT_ListWarden.prototype.enableSandboxUpdates = function() {
- this.listManager_.enableUpdateTables(this.sandboxUpdates_);
- }
- PROT_ListWarden.prototype.disableSandboxUpdates = function() {
- this.listManager_.disableUpdateTables(this.sandboxUpdates_);
- }
- PROT_ListWarden.prototype.registerBlackTable = function(tableName) {
- var result = this.listManager_.registerTable(tableName);
- if (result)
- this.blackTables_.push(tableName);
- return result;
- }
- PROT_ListWarden.prototype.registerWhiteTable = function(tableName) {
- var result = this.listManager_.registerTable(tableName);
- if (result)
- this.whiteTables_.push(tableName);
- return result;
- }
- PROT_ListWarden.prototype.registerSandboxUpdate = function(tableName, callback) {
- var result = this.listManager_.registerTable(tableName,
- true, /* requireMac */
- callback);
- if (result)
- this.sandboxUpdates_.push(tableName);
- return result;
- }
- PROT_ListWarden.prototype.isURLInTables_ = function(tables, url) {
- for (var i = 0; i < tables.length; ++i) {
- if (this.listManager_.safeLookup(tables[i], url))
- return true;
- }
- return false;
- }
- PROT_ListWarden.prototype.isWhiteURL_ = function(url) {
- if (!this.listManager_)
- return false;
- var whitelisted = this.isURLInTables_(this.whiteTables_, url);
- if (whitelisted)
- G_Debug(this, "Whitelist hit: " + url);
- return whitelisted;
- }
- PROT_ListWarden.prototype.isWhiteURL = function(url) {
- return this.isWhiteURL_(url);
- }
- PROT_ListWarden.prototype.isBlackURL_ = function(url) {
- if (!this.listManager_)
- return false;
- var blacklisted = this.isURLInTables_(this.blackTables_, url);
- if (blacklisted)
- G_Debug(this, "Blacklist hit: " + url);
- return blacklisted;
- }
- PROT_ListWarden.prototype.isEvilURL_ = function(url) {
- return !this.isWhiteURL_(url) && this.isBlackURL_(url);
- }
- function TEST_PROT_ListWarden() {
- if (G_GDEBUG) {
- var z = "listwarden UNITTEST";
- G_debugService.enableZone(z);
- G_Debug(z, "Starting");
- var listManager = new PROT_ListManager(true /* testing */);
- var warden = new PROT_ListWarden(listManager);
- G_Assert(z, warden.registerWhiteTable("test-white-domain"),
- "Failed to register test-white-domain table");
- G_Assert(z, warden.registerBlackTable("test-black-url"),
- "Failed to register test-black-url table");
- listManager.safeInsert("test-white-domain", "foo.com", "1");
- listManager.safeInsert("test-black-url", "http://foo.com/good/1", "1");
- listManager.safeInsert("test-black-url", "http://foo.com/bad/1", "1");
- G_Assert(z, !warden.isEvilURL_("http://foo.com/good/1"),
- "White listing is not working.");
- G_Assert(z, warden.isBlackURL_("http://foo.com/bad/1"),
- "Black listing is not working.");
- G_Assert(z, !warden.isEvilURL_("http://foo.com/bad/1"),
- "Whitelist should have priority.");
- G_Debug(z, "PASSED");
- }
- }
-